import request from './http.js'

/** 
 * 请求二次封装
 */
const api = {
	// 查询openid
	searchOpenid(data) {
		return request({
			url: '/wx/miniapp/login',
			method: 'POST',
			data
		})
	},
	
	// 获取微信手机号
	getWxPhoneNumber(data) {
		return request({
			url: '/wx/miniapp/phone',
			method: 'POST',
			data
		})
	},

	// 获取用户信息
	getUserInfo() {
		return request({
			url: '/api/user/info',
			method: 'GET'
		})
	},

	// 商品分类
	getCategoryList(params) {
		return request({
			url: '/business/category/list',
			method: 'GET',
			data: params
		})
	},

	// 商品
	getGoodsList(params) {
		return request({
			url: '/business/goods/list',
			method: 'GET',
			data: params
		})
	},

	// 获取商品详情
	getGoodsDetail(goodsId) {
		return request({
			url: `/business/goods/${goodsId}`,
			method: 'GET'
		})
	},

	// 添加商品
	addGoods(params) {
		return request({
			url: '/business/goods',
			method: 'POST',
			data: params
		})
	},

	// 更新商品
	updateGoods(goodsId, params) {
		return request({
			url: `/business/goods`,
			method: 'PUT',
			data: params
		})
	},

	// 删除商品
	deleteGoods(goodsId) {
		return request({
			url: `/business/goods/${goodsId}`,
			method: 'DELETE'
		})
	},

	listSupplier(query) {
		return request({
			url: '/business/supplier/list',
			method: 'GET',
			data: query
		})
	},

	// 添加供应商
	addSupplier(params) {	
		return request({
			url: '/business/supplier',
			method: 'POST',
			data: params
		})
	},

	// 新增进货单
	addPurchase(params) {
		return request({
			url: '/business/receipt',
			method: 'POST',
			data: params
		})
	},
	
	// 获取进货单详情
	getPurchaseDetail(id) {
		return request({
			url: `/business/receipt/${id}`,
			method: 'GET'
		})
	},

	// 更新进货单
	updatePurchase( params) {
		return request({
			url: `/business/receipt`,
			method: 'PUT',
			data: params
		})
	},

	// 删除进货单
	deletePurchase(id) {
		return request({
			url: `/business/receipt/${id}`,
			method: 'DELETE'
		})
	},

	// 查询进货单列表
	listPurchase(params) {
		return request({
			url: '/business/receipt/list',
			method: 'GET',
			data: params
		})
	},

	// 根据进货单编号查询商品列表
	getGoodsListByReceiptCode(receiptCode) {
		return request({
		  url: '/business/receipt/items/' + receiptCode,
		  method: 'GET'
		})
	},

	getSupplier(id) {
		return request({
			url: `/business/supplier/${id}`,
			method: 'GET'
		})
	},
	updateSupplier(params) {
		return request({
			url: '/business/supplier',
			method: 'PUT',
			data: params
		})
	},

	// 查询定子查询列表
	listCore(query) {
		return request({
			url: '/business/core/list',
			method: 'GET',
			data: query
		})
	},

	// 获取定子详情
	getCoreDetail(id) {
		return request({
			url: `/business/core/${id}`,
			method: 'GET'
		})
	},

	// 添加定子
	addCore(params) {
		return request({
			url: '/business/core',
			method: 'POST',
			data: params
		})
	},

	// 更新定子
	updateCore(params) {
		return request({
			url: '/business/core',
			method: 'PUT',
			data: params
		})
	},

	// 删除定子
	deleteCore(id) {
		return request({
			url: `/business/core/${id}`,
			method: 'DELETE'
		})
	},

	// 转子
	listShaftspecifications(query) {
		return request({
			url: '/business/shaftspecifications/list',
			method: 'GET',
			data: query
		})
	},

	// 获取转子详情
	getShaftDetail(id) {
		return request({
			url: `/business/shaftspecifications/${id}`,
			method: 'GET'
		})
	},

	// 添加转子
	addShaft(params) {
		return request({
			url: '/business/shaftspecifications',
			method: 'POST',
			data: params
		})
	},

	// 更新转子
	updateShaft(params) {
		return request({
			url: '/business/shaftspecifications',
			method: 'PUT',
			data: params
		})
	},

	// 删除转子
	deleteShaft(id) {
		return request({
			url: `/business/shaftspecifications/${id}`,
			method: 'DELETE'
		})
	},

	// 配件
	listParts(query) {
		return request({
			url: '/business/parts/list',
			method: 'GET',
			data: query
		})
	},

	// 获取配件详情
	getPartsDetail(id) {
		return request({
			url: `/business/parts/${id}`,
			method: 'GET'
		})
	},

	// 添加配件
	addParts(params) {
		return request({
			url: '/business/parts',
			method: 'POST',
			data: params
		})
	},

	// 更新配件
	updateParts(params) {
		return request({
			url: '/business/parts',
			method: 'PUT',
			data: params
		})
	},

	// 删除配件
	deleteParts(id) {
		return request({
			url: `/business/parts/${id}`,
			method: 'DELETE'
		})
	},

	// ==================== 明细管理 ====================
	// 获取销售/出货明细列表
	getOutboundList(params) {
		return request({
			url: '/business/outbound/list',
			method: 'GET',
			data: params
		})
	},

	// 获取退货明细列表
	getReturnedList(params) {
		return request({
			url: '/business/returned/list',
			method: 'GET',
			data: params
		})
	},

	// 获取收款明细列表
	getPaymentList(params) {
		return request({
			url: '/business/payment/list',
			method: 'GET',
			data: params
		})
	},

	// 获取所有明细列表（包括出货、退货、收款）
	getDetailList(params) {
		// 根据明细类型调用不同的接口
		if (params.type === 'outbound') {
			return this.getOutboundList(params);
		} else if (params.type === 'returned') {
			return this.getReturnedList(params);
		} else if (params.type === 'payment') {
			return this.getPaymentList(params);
		}
		// 默认返回出货明细
		return this.getOutboundList(params);
	},

	// 删除出货单
	deleteSales(id) {
		return request({
			url: `/business/sales/${id}`,
			method: 'DELETE'
		})
	},
	

	// 获取收货地址
	getAddressList(params) {
		return request({
			url: '/wx/miniapp/address/list',
			method: 'GET',
			data: params
		})
	},

	// 获取收货地址详情
	getAddressDetail(params) {
		return request({
			url: '/wx/miniapp/address/detail',
			method: 'GET',
			data: params
		})
	},

	// 新增收货地址
	addAddress(params) {
		return request({
			url: '/wx/miniapp/address/add',
			method: 'POST',
			data: params
		})
	},

	// 更新收货地址
	updateAddress(params) {
		return request({
			url: '/wx/miniapp/address/update',
			method: 'POST',
			data: params
		})
	},

	// 删除收货地址
	deleteAddress(params) {
		return request({
			url: `/wx/miniapp/address/delete/${params}`,
			method: 'POST',
			// data: params
		})
	},

	// ==================== 客户管理 ====================
	// 获取客户列表
	listCustomer(params) {
		return request({
			url: '/business/customer/list',
			method: 'GET',
			data: params
		})
	},

	// 获取客户详情
	getCustomer(id) {
		return request({
			url: `/business/customer/${id}`,
			method: 'GET'
		})
	},

	// 新增客户
	addCustomer(params) {
		return request({
			url: '/business/customer',
			method: 'POST',
			data: params
		})
	},

	// 更新客户
	updateCustomer(params) {
		return request({
			url: '/business/customer',
			method: 'PUT',
			data: params
		})
	},

	// 删除客户
	deleteCustomer(id) {
		return request({
			url: `/business/customer/${id}`,
			method: 'DELETE'
		})
	},

	// 获取客户分类树形数据
	listCustomerCategory() {
		return request({
			url: '/business/customer/category/list',
			method: 'GET'
		})
	},

	// ==================== 销售管理 ====================
	// 新增销售单
	addSales(data) {
		return request({
			url: '/business/sales',
			method: 'POST',
			data: data
		})
	},

	// 更新销售单
	updateSales(data) {
		return request({
			url: '/business/sales',
			method: 'PUT',
			data: data
		})
	},
	// 获取销售单列表
	listSales(params) {
		return request({
			url: '/business/sales/list',
			method: 'GET',
			data: params
		})
	},

	// 获取销售单详情
	getSalesDetail(id) {
		return request({
			url: `/business/sales/${id}`,
			method: 'GET'
		})
	},

	// 意见反馈
	submitQuestion(data) {
		return request({
			url: '/business/feedback',
			method: 'POST',
			data: data
		})
	},

	// 支付
	payMoney(data){
		return request({
			url: '/api/v1/wxpay/prePay',
			method: 'POST',
			// data: data
		})
	}
}

export default api;